package com.pointi.emoServerM;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.pointi.emoTools.emoLicense;

public class ConfigurationData extends emoLicense
{
	// EMOTION_SERVER
	public String s_server_no = "" ;
	public String s_manager_limit = "" ;
	public String s_worker_limit = "" ;
	public String s_check_interval = "" ;

	public String s_insert_mode = "" ;
	public String s_conatiner_size = "" ;

	public ConfigurationData() { }

	public void InitializeData()
	{
		// EMOTION_SERVER
		s_server_no = "" ;
		s_manager_limit = "" ;
		s_worker_limit = "" ;
		s_check_interval = "" ;
		s_insert_mode = "" ;
		s_conatiner_size = "" ;
		super.InitializeData() ;
	}

	public ConfigurationData ReadConfXML(String strFile) throws Exception
	{
		NodeList mCATEGORY = null ;
		Node mNode = null ;
		ConfigurationData conf_data = new ConfigurationData() ;
		try
		{
			Document doc = super.ReadConfXML(strFile, conf_data) ;
			doc.getDocumentElement().normalize();
			if (doc.getDocumentElement().getNodeName().equals("configuration"))
			{
				// CONF | CATEGORY | EMOTION_SERVER
				mCATEGORY = doc.getElementsByTagName("emotion_server") ;
				mNode = mCATEGORY.item(0) ;
				if (mNode.getNodeType() == Node.ELEMENT_NODE)
				{
					Element mElmnt = (Element) mNode ; // TYPE_CAST
					conf_data.s_server_no = fnReadTerminal(mElmnt, "server_no") ;
					conf_data.s_manager_limit = fnReadTerminal(mElmnt, "manager_limit") ;
					conf_data.s_worker_limit = fnReadTerminal(mElmnt, "worker_limit") ;
					conf_data.s_check_interval = fnReadTerminal(mElmnt, "check_interval") ;
					conf_data.s_insert_mode = fnReadTerminal(mElmnt, "insert_mode") ;
					conf_data.s_conatiner_size = fnReadTerminal(mElmnt, "container_size") ;
				}
			}
		} catch (Exception e) { e.printStackTrace() ; }		
		return conf_data;
	}

	public void WriteLogConfigurationData(ConfigurationData conf_data)
	{
		super.WriteLogConfigurationData(conf_data) ;
		System.out.println("--------------- emotionclient ---------------");
		System.out.println("serverno	: " + conf_data.s_server_no);
		System.out.println("mngerlimit	: " + conf_data.s_manager_limit);
		System.out.println("workerlimit	: " + conf_data.s_worker_limit);
		System.out.println("chkinterval	: " + conf_data.s_check_interval);
		System.out.println("insertmode	: " + conf_data.s_insert_mode);
		System.out.println("conatinerSZ	: " + conf_data.s_conatiner_size);
		System.out.println("---------------------------------------------");
	}
}
